﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubMusicCtrl : MonoBehaviour
{
        [Header("背景音乐")]
        public AudioSource asBgm;
        [Header("弹出音效")]
        public AudioSource asShow;

        [Header("音乐可视化")]
        public GameObject msee;

        public bool enableMusic = true;
        private bool enableBackup = true;

        public float volMusic = 80f;
        private float volBackup = 100f;

        void Start()
        {
                if (enableMusic)
                {
                        if (asBgm)
                        {
                                asBgm.Play();
                                asBgm.volume = 0f;
                        }
                }
        }

        void Update()
        {
                if (volMusic != volBackup)
                {
                        volBackup = volMusic;
                        asBgm.volume = volBackup/100f;
                        asShow.volume = volBackup/100f;
                }

                if (enableBackup != enableMusic)
                {
                        enableBackup = enableMusic;
                        if (enableBackup)
                        {
                                asBgm.Play();
                        }
                        else
                        {
                                asBgm.Pause();
                        }

                        //音乐可视化
                        if (msee)
                        {
                                msee.SetActive(enableMusic);
                        }
                }
        }

        public void SettingMusic()
        {
                if (enableMusic)
                {
                        asShow.Play();
                }
        }


}
